<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>AK JOB</title>
    <link rel="icon" type="image/x-icon" href="../../../layuiadmin/style/res/favicon.png"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="LAY-role-manage" lay-filter="LAY-role-manage"></table>
        </div>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <button class="layui-btn layui-btn-sm" lay-event="addApplication">新建</button>
</script>

<script type="text/html" id="onLineClientCountTmp">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="onLineCount">{{ d.onLineClientCount }}</a>
</script>

<script type="text/html" id="table-tool">
    {{#  if(d.id !== 'public'){ }}
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {{#  } }}

</script>


<script src="../../../layuiadmin/layui/layui.js"></script>
<script src="../../../layuiadmin/lib/juicer-min.js"></script>

<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'namespace', 'table', 'setter', 'auth', 'AppHelper', 'routerHelper', 'tableWraper'], function () {
        var $ = layui.$
            , form = layui.form
            , namespace = layui.namespace
            , setter = layui.setter
            , table = layui.table
            , routerHelper = layui.routerHelper
            , tableWraper = layui.tableWraper
            , AppHelper = layui.AppHelper
            , LayerPage = AppHelper.getLayerPage()
        ;


        //初始化表格
        var currentTable = tableWraper.render({
            elem: "#LAY-role-manage",
            toolbar: '#toolbarDemo',
            url: setter.apiHost + "/admin/api/akNamespace/pageList",
            cols: [[
                {title: "id", field: 'id', search: true}
                , {title: "名称", field: 'name', search: true}
                , {title: "描述", field: 'namespaceDes'}
                , {title: "应用数量", field: 'applicationCount'}
                , {title: "创建时间", field: 'createTime', width: 200}
                , {fixed: 'right', title: "操作", align: 'center', toolbar: '#table-tool', width: 200}
            ]]
        });

        table.on('toolbar(LAY-role-manage)', function(obj){
            switch(obj.event){
                case 'addApplication':
                    var path = routerHelper.jump({
                        path: "namespace_form.html"
                        , query: {
                            action: "add"
                        }
                    })

                    LayerPage.open({
                        path: path
                        , title: "新建"
                        , iframeSubmitId: "#namespaceFormSubmit"
                    })
                    break;
            };
        });

        table.on("tool(LAY-role-manage)", function (obj) {
            var event = obj.event;
            var data = obj.data;
            var id = data.id;
            let that = this;
            switch (event) {
                case "edit":
                    var path = routerHelper.jump({
                        path: "namespace_form.html"
                        , query: {
                            action: "edit"
                            , id: id
                        }
                    })

                    LayerPage.open({
                        path: path
                        , title: "编辑"
                        , iframeSubmitId: "#namespaceFormSubmit"
                    })

                    break;
                case "del":
                    layer.confirm("删除后不可恢复，您确定要删除吗？", {icon: 0}, function (index) {
                        var loadIndex = layer.load(2);
                        namespace.methods.del(id).always(function () {
                            layer.close(loadIndex);
                        }).done(function (res) {
                            if (res.data > 0) {
                                layer.msg("删除成功!", {icon: 1});
                            }
                            layer.close(index);
                            currentTable.reload();
                        });
                    })
                    break;
            }
        })

    });
</script>
</body>
</html>
